﻿Namespace nHibernate.Models
    Public Class OrderedArticleModel
        Public Sub New()

        End Sub

        Public Overridable Property OrderArticleIDWithOrderID As String

        ''' <summary>
        ''' The GUID
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Overridable Property OrderArticleID As String
        ''' <summary>
        ''' The original articleid
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Overridable Property Article As ArticleModel
        Public Overridable Property OrderedAmount As Decimal
        Public Overridable Property OrderRebate As Decimal
        Public Overridable Property OrderPriceAmount As Decimal
        Public Overridable Property OrderPriceIsGross As Boolean
        Public Overridable Property OrderPriceCurrency As Integer
        Public Overridable Property OrderPosition As Integer
        Public Overridable Property OrderText As String

        Public Overridable Function ToOrderedArticle() As OrderedArticle
            Return New OrderedArticle(Article.ToArticle) With {.OrderedAmount = OrderedAmount, .OrderRebate = OrderRebate, .OrderPosition = OrderPosition, .OrderText = OrderText, .OrderPrice = New EMoney(OrderPriceAmount, OrderPriceIsGross, OrderPriceCurrency)}
        End Function

        Public Shared Function FromOrderedArticle(oa As OrderedArticle, orderid As String) As OrderedArticleModel
            Dim t = New OrderedArticleModel With {.OrderArticleIDWithOrderID = orderid + "-" + oa.OrderArticleID, .OrderArticleID = oa.OrderArticleID, .OrderedAmount = oa.OrderedAmount, .OrderRebate = oa.OrderRebate, _
                                                 .OrderPriceAmount = oa.OrderPrice.Amount, .OrderPriceCurrency = oa.OrderPrice.Currency, .OrderPriceIsGross = oa.OrderPrice.IsGross, .OrderPosition = oa.OrderPosition, .OrderText = .OrderText}
            t.Article = New ArticleModel With {.ArticleID = oa.ArticleID, .ArticleDescription = oa.ArticleDescription, .ArticleCategory = oa.ArticleCategory, .ArticlePrice1Amount = oa.ArticlePrice1.Amount, .ArticlePrice1Currency = oa.ArticlePrice1.Currency, .ArticlePrice1IsGross = oa.ArticlePrice1.IsGross, _
                                          .ArticlePrice2Amount = oa.ArticlePrice1.Amount, .ArticlePrice2Currency = oa.ArticlePrice1.Currency, .ArticlePrice2IsGross = oa.ArticlePrice1.IsGross, _
                                          .ArticlePrice3Amount = oa.ArticlePrice1.Amount, .ArticlePrice3Currency = oa.ArticlePrice1.Currency, .ArticlePrice3IsGross = oa.ArticlePrice1.IsGross, _
                                          .ArticleText = oa.ArticleText, .ArticleUnit = oa.ArticleUnit, .ArticleWeight = oa.WeightString, .TaxClass = oa.TaxClass}
            Return t
        End Function
    End Class
End Namespace
